﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IOT4Week1Day1.Domain.Models;
using IOT4Week1Day1.Domain.IRepositories;
using Microsoft.EntityFrameworkCore;

namespace IOT4Week1Day1.EFCore.Repositories
{
    /// <summary>
    /// 数据字典的仓储接口
    /// </summary>
    public class DictKeyRepository : EfRepository<DictKey>, IDictKeyRepository
    {
        private readonly MyDbContext _db;

        public DictKeyRepository(MyDbContext db) : base(db)
        {
            _db = db;
        }

        /// <summary>
        /// 贪婪加载指定名字的字典项
        /// </summary>
        /// <param name="dictName">字典名称</param>
        /// <returns></returns>
        public List<DictKey> GetDicts(string dictName)
        {
            var list = _db.DictKeys.Include(x => x.DictItems)
                              .Where(x => string.IsNullOrEmpty(dictName) || x.DictName.Equals(dictName))
                              .ToList();

            return list;
        }

    }
}
